package Controlers;

import java.awt.Dimension;
import java.util.ArrayList;
import Invaders.Boss;
import Invaders.Invader;
import Invaders.InvaderHorizontal;
import Invaders.InvaderTeleporter;
import Invaders.InvaderVertical;
import Invaders.InvaderZigzag;

public class InvaderControler {

	private Dimension dimension;
	private ArrayList<Invader> invasores;
	private int NUM_HORIZONTAL_TOTAL;
	private int NUM_VERTICAL_TOTAL;
	private int NUM_DIAGONAL_TOTAL;
	private int NUM_ZIGZAG_TOTAL;
	private int NUM_TELEPORTER_TOTAL;
	private int NUM_BOSS_TOTAL;
	private int NUM_HORIZONTAL_ATUAL;
	private int NUM_VERTICAL_ATUAL;
	private int NUM_DIAGONAL_ATUAL;
	private int NUM_ZIGZAG_ATUAL;
	private int NUM_TELEPORTER_ATUAL;
	private int NUM_BOSS_ATUAL;
	private InvaderHorizontal invaderHorizontalTeste;
	private InvaderVertical invaderVerticalTeste;
	private Invader invaderDiagonalTeste;
	private InvaderZigzag invaderZigZagTeste;
	private InvaderTeleporter invaderTeleporterTeste;
	private Boss bossTeste;
	
	public InvaderControler(ArrayList<Invader> invasores, int largura, int altura) {
		this.invasores = invasores;
		NUM_HORIZONTAL_ATUAL = 0;
		NUM_VERTICAL_ATUAL = 0;
		NUM_DIAGONAL_ATUAL = 0;
		NUM_ZIGZAG_ATUAL = 0;
		NUM_TELEPORTER_ATUAL = 0;
		this.dimension = new Dimension(largura, altura);
		invaderHorizontalTeste = new InvaderHorizontal(dimension);
		invaderVerticalTeste = new InvaderVertical(dimension);
		invaderDiagonalTeste = new Invader(dimension);
		invaderZigZagTeste = new InvaderZigzag(dimension);
		invaderTeleporterTeste = new InvaderTeleporter(dimension);
		bossTeste = new Boss(dimension);
	}
	
	
	
	public void criaInvader(int level, int tempo) {
		
		setNumInvaders(level);
		if(tempo%10 == 0 &&	tempo != 0) {
			NUM_HORIZONTAL_ATUAL = 0;
			for (int i = 0; i < invasores.size(); i++) {
				if(invasores.get(i).getClass() == invaderHorizontalTeste.getClass()) {
					NUM_HORIZONTAL_ATUAL++;
				}
			}
			NUM_VERTICAL_ATUAL = 0;
			for (int i = 0; i < invasores.size(); i++) {
				if(invasores.get(i).getClass() == invaderVerticalTeste.getClass()) {
					NUM_VERTICAL_ATUAL++;
				}
			}
			NUM_DIAGONAL_ATUAL = 0;
			for (int i = 0; i < invasores.size(); i++) {
				if(invasores.get(i).getClass() == invaderDiagonalTeste.getClass()) {
					NUM_DIAGONAL_ATUAL++;
				}
			}
			NUM_ZIGZAG_ATUAL = 0;
			for (int i = 0; i < invasores.size(); i++) {
				if(invasores.get(i).getClass() == invaderZigZagTeste.getClass()) {
					NUM_ZIGZAG_ATUAL++;
				}
			}
			NUM_TELEPORTER_ATUAL = 0;
			for (int i = 0; i < invasores.size(); i++) {
				if(invasores.get(i).getClass() == invaderTeleporterTeste.getClass()) {
					NUM_TELEPORTER_ATUAL++;
				}
			}
			NUM_BOSS_ATUAL = 0;
			for (int i = 0; i < invasores.size(); i++) {
				if(invasores.get(i).getClass() == bossTeste.getClass()) {
					NUM_BOSS_ATUAL++;
				}
			}
			for (int i = 0; i < (NUM_HORIZONTAL_TOTAL - NUM_HORIZONTAL_ATUAL); i++) {
				invasores.add(new InvaderHorizontal(dimension));
			}
			for (int i = 0; i < NUM_VERTICAL_TOTAL - NUM_VERTICAL_ATUAL; i++) {
				invasores.add(new InvaderVertical(dimension));
			}
			for (int i = 0; i < (NUM_DIAGONAL_TOTAL - NUM_DIAGONAL_ATUAL); i++) {
				invasores.add(new Invader(dimension));
			}
			for (int i = 0; i < (NUM_ZIGZAG_TOTAL - NUM_ZIGZAG_ATUAL); i++) {
				invasores.add(new InvaderZigzag(dimension));
			}
			for (int i = 0; i < (NUM_TELEPORTER_TOTAL - NUM_TELEPORTER_ATUAL); i++) {
				invasores.add(new InvaderTeleporter(dimension));
			}
			for (int i = 0; i < (NUM_BOSS_TOTAL - NUM_BOSS_ATUAL); i++) {
				invasores.add(new Boss(dimension));
			}
			
		}
	}
	
	public void setNumInvaders(int level) {
		
		switch(level) {
			case 1:
				NUM_HORIZONTAL_TOTAL = 10;
				NUM_VERTICAL_TOTAL = 10;
				NUM_DIAGONAL_TOTAL = 0;
				NUM_ZIGZAG_TOTAL = 0;
				NUM_TELEPORTER_TOTAL = 0;
				NUM_BOSS_TOTAL = 0;
				break;
			case 2:
				NUM_HORIZONTAL_TOTAL = 5;
				NUM_VERTICAL_TOTAL = 5;
				NUM_DIAGONAL_TOTAL = 10;
				NUM_ZIGZAG_TOTAL = 0;
				NUM_TELEPORTER_TOTAL = 0;
				NUM_BOSS_TOTAL = 0;
				break;
			case 3:
				NUM_HORIZONTAL_TOTAL = 2;
				NUM_VERTICAL_TOTAL = 2;
				NUM_DIAGONAL_TOTAL = 14;
				NUM_ZIGZAG_TOTAL = 0;
				NUM_TELEPORTER_TOTAL = 0;
				NUM_BOSS_TOTAL = 0;
				break;
			case 4:
				NUM_HORIZONTAL_TOTAL = 0;
				NUM_VERTICAL_TOTAL = 0;
				NUM_DIAGONAL_TOTAL = 12;
				NUM_ZIGZAG_TOTAL = 8;
				NUM_TELEPORTER_TOTAL = 0;
				NUM_BOSS_TOTAL = 0;
				break;
			case 5:
				NUM_HORIZONTAL_TOTAL = 0;
				NUM_VERTICAL_TOTAL = 0;
				NUM_DIAGONAL_TOTAL = 4;
				NUM_ZIGZAG_TOTAL = 12;
				NUM_TELEPORTER_TOTAL = 8;
				NUM_BOSS_TOTAL = 0;
				break;
			case 6:
				NUM_HORIZONTAL_TOTAL = 0;
				NUM_VERTICAL_TOTAL = 0;
				NUM_DIAGONAL_TOTAL = 0;
				NUM_ZIGZAG_TOTAL = 8;
				NUM_TELEPORTER_TOTAL = 12;
				NUM_BOSS_TOTAL = 0;
				break;
			case 7:
				NUM_HORIZONTAL_TOTAL = 2;
				NUM_VERTICAL_TOTAL = 3;
				NUM_DIAGONAL_TOTAL = 5;
				NUM_ZIGZAG_TOTAL = 3;
				NUM_TELEPORTER_TOTAL = 3;
				NUM_BOSS_TOTAL = 2;
				break;
		}
	}
}
